|
1
|
|
|
var args = require('yargs').argv; |
|
2
|
|
|
var autoprefixer = require('gulp-autoprefixer'); |
|
3
|
|
|
var bump = require('gulp-bump'); |
|
4
|
|
|
var checktextdomain = require('gulp-checktextdomain'); |
|
5
|
|
|
var concat = require('gulp-concat'); |
|
6
|
|
|
var cssnano = require('gulp-cssnano'); |
|
7
|
|
|
var gulp = require('gulp'); |
|
8
|
|
|
var gulpif = require('gulp-if'); |
|
9
|
|
|
var jshint = require('gulp-jshint'); |
|
10
|
|
|
var mergeStream = require('merge-stream'); |
|
11
|
|
|
var potomo = require('gulp-potomo'); |
|
12
|
|
|
var pottopo = require('gulp-pottopo'); |
|
13
|
|
|
var pump = require('pump'); |
|
14
|
|
|
var sass = require('gulp-sass'); |
|
15
|
|
|
var sort = require('gulp-sort'); |
|
16
|
|
|
var uglify = require('gulp-uglify'); |
|
17
|
|
|
var wpPot = require('gulp-wp-pot'); |
|
18
|
|
|
var yaml = require('yamljs'); |
|
19
|
|
|
|
|
20
|
|
|
var config = yaml.load('+/config.yml'); |
|
21
|
|
|
|
|
22
|
|
|
gulp.task('bump', function(cb) { |
|
23
|
|
|
var type = 'patch'; |
|
24
|
|
|
['prerelease','patch','minor','major'].some(function(arg) { |
|
25
|
|
|
if( !args[arg] )return; |
|
26
|
|
|
type = arg; |
|
27
|
|
|
return true; |
|
28
|
|
|
}); |
|
29
|
|
|
pump([ |
|
30
|
|
|
gulp.src(config.bump), |
|
31
|
|
|
bump({type:type,keys:['stable tag','version']}), |
|
32
|
|
|
gulp.dest('.'), |
|
33
|
|
|
], cb); |
|
34
|
|
|
}); |
|
35
|
|
|
|
|
36
|
|
|
gulp.task('js', function(cb) { |
|
37
|
|
|
var streams = mergeStream(); |
|
38
|
|
|
for(var key in config.scripts) { |
|
39
|
|
|
if(!config.scripts.hasOwnProperty(key))continue; |
|
40
|
|
|
streams.add(gulp.src(config.scripts[key]).pipe(concat(key))); |
|
41
|
|
|
} |
|
42
|
|
|
pump([ |
|
43
|
|
|
streams, |
|
44
|
|
|
gulpif(args.production, uglify({ |
|
45
|
|
|
mangle: {properties: {regex: /[a-zA-Z]+_$/}}, |
|
46
|
|
|
// output: {comments: 'some'}, |
|
47
|
|
|
})), |
|
48
|
|
|
gulp.dest(config.dest.js), |
|
49
|
|
|
], cb); |
|
50
|
|
|
}); |
|
51
|
|
|
|
|
52
|
|
|
gulp.task('jshint', function(cb) { |
|
53
|
|
|
pump([ |
|
54
|
|
|
gulp.src(config.watch.js), |
|
55
|
|
|
jshint(), |
|
56
|
|
|
jshint.reporter('jshint-stylish'), |
|
57
|
|
|
jshint.reporter('fail'), |
|
58
|
|
|
], cb); |
|
59
|
|
|
}); |
|
60
|
|
|
|
|
61
|
|
|
gulp.task('po-to-mo', function(cb) { |
|
62
|
|
|
pump([ |
|
63
|
|
|
gulp.src(config.dest.lang + '*.po'), |
|
64
|
|
|
potomo(), |
|
65
|
|
|
gulp.dest(config.dest.lang), |
|
66
|
|
|
], cb); |
|
67
|
|
|
}); |
|
68
|
|
|
|
|
69
|
|
|
gulp.task('pot', function(cb) { |
|
70
|
|
|
pump([ |
|
71
|
|
|
gulp.src(config.watch.php), |
|
72
|
|
|
checktextdomain({ |
|
73
|
|
|
text_domain: config.language.domain, |
|
74
|
|
|
keywords: [ |
|
75
|
|
|
'__:1,2d', |
|
76
|
|
|
'_e:1,2d', |
|
77
|
|
|
'_x:1,2c,3d', |
|
78
|
|
|
'esc_html__:1,2d', |
|
79
|
|
|
'esc_html_e:1,2d', |
|
80
|
|
|
'esc_html_x:1,2c,3d', |
|
81
|
|
|
'esc_attr__:1,2d', |
|
82
|
|
|
'esc_attr_e:1,2d', |
|
83
|
|
|
'esc_attr_x:1,2c,3d', |
|
84
|
|
|
'_ex:1,2c,3d', |
|
85
|
|
|
'_n:1,2,4d', |
|
86
|
|
|
'_nx:1,2,4c,5d', |
|
87
|
|
|
'_n_noop:1,2,3d', |
|
88
|
|
|
'_nx_noop:1,2,3c,4d', |
|
89
|
|
|
], |
|
90
|
|
|
}), |
|
91
|
|
|
sort(), |
|
92
|
|
|
wpPot({ |
|
93
|
|
|
domain: config.language.domain, |
|
94
|
|
|
lastTranslator: config.language.translator, |
|
95
|
|
|
team: config.language.team, |
|
96
|
|
|
}), |
|
97
|
|
|
gulp.dest(config.dest.lang + config.language.domain + '.pot'), |
|
98
|
|
|
], cb); |
|
99
|
|
|
}); |
|
100
|
|
|
|
|
101
|
|
|
gulp.task('pot-to-po', function(cb) { |
|
102
|
|
|
pump([ |
|
103
|
|
|
gulp.src(config.dest.lang + '*.pot'), |
|
104
|
|
|
pottopo(), |
|
105
|
|
|
gulp.dest(config.dest.lang), |
|
106
|
|
|
], cb); |
|
107
|
|
|
}); |
|
108
|
|
|
|
|
109
|
|
|
gulp.task('scss', function(cb) { |
|
110
|
|
|
pump([ |
|
111
|
|
|
gulp.src(config.watch.scss), |
|
112
|
|
|
sass({ |
|
113
|
|
|
outputStyle: 'expanded', |
|
114
|
|
|
}).on('error', sass.logError), |
|
115
|
|
|
autoprefixer('last 2 versions'), |
|
116
|
|
|
gulpif(args.production, cssnano({ |
|
117
|
|
|
minifyFontValues: false, |
|
118
|
|
|
discardComments: {removeAll: true}, |
|
119
|
|
|
zindex: false, |
|
120
|
|
|
})), |
|
121
|
|
|
gulp.dest(config.dest.css), |
|
122
|
|
|
], cb); |
|
123
|
|
|
}); |
|
124
|
|
|
|
|
125
|
|
|
gulp.task('watch', function() { |
|
126
|
|
|
gulp.watch(config.watch.js, gulp.parallel('jshint', 'js')); |
|
127
|
|
|
gulp.watch(config.watch.scss, gulp.parallel('scss')); |
|
128
|
|
|
}); |
|
129
|
|
|
|
|
130
|
|
|
gulp.task('languages', gulp.series('pot', 'pot-to-po', 'po-to-mo')); |
|
131
|
|
|
gulp.task('default', gulp.parallel('scss', 'jshint', 'js')); |
|
132
|
|
|
gulp.task('build', gulp.parallel('default', 'languages')); |
|
133
|
|
|
|